home *** CD-ROM | disk | FTP | other *** search
/ Chip 2003 October / Chip Ekim 2003.iso / prog / code / contr / setup.exe / Disk1 / data1.cab / Configuration_En / Commands / ccFormatTable.js < prev    next >
Encoding:
JavaScript  |  2003-07-18  |  21.5 KB  |  587 lines

  1. // Copyright 1998, 1999, 2000, 2001, 2002, 2003 Macromedia, Inc. All rights reserved.
  2.  
  3. // *************** GLOBAL VARS  *****************
  4.  
  5. var helpDoc = MM.HELP_cmdFormatTable;
  6. var DEFAULT_tableStyle = 7;
  7. //these constants used in tableFormats.js file when defining new table formats
  8. var NONE=0,LEFT=1,CENTER=2,RIGHT=3,BOLD=1,ITALIC=2,BOLD_ITALIC=3;
  9. var ORIGINAL_PREVIEW_TABLE = getPreviewTable().outerHTML;
  10.  
  11. //******************* API **********************
  12.  
  13.  
  14. //*************** Pg1 Class *****************
  15.  
  16. //This is an example of a page class to be used with the TabControl.
  17. //Uncomment the alert() calls to display the various events as they occur.
  18.  
  19. function Pg1(theTabLabel) {
  20.   this.tabLabel = theTabLabel;
  21. }
  22. Pg1.prototype.getTabLabel = Pg1_getTabLabel;
  23. function Pg1_getTabLabel() {
  24.   return this.tabLabel;
  25. }
  26.  
  27. //***************** End of Pg1 Class ******************
  28. //*************** Pg2 Class *****************
  29.  
  30. //This is an example of a page class to be used with the TabControl.
  31. //Uncomment the alert() calls to display the various events as they occur.
  32.  
  33. function Pg2(theTabLabel) {
  34.   this.tabLabel = theTabLabel;
  35. }
  36. Pg2.prototype.getTabLabel = Pg2_getTabLabel;
  37. function Pg2_getTabLabel() {
  38.   return this.tabLabel;
  39. }
  40.  
  41. //***************** End of Pg2 Class ******************
  42.  
  43.  
  44. function commandButtons(){
  45.   var tableObj = findTable();
  46. /*  var Buttons=new Array(MM.BTN_OK,        "applyFormatToSelectedTable();window.close();",
  47.                         MM.BTN_Apply,     "applyFormatToSelectedTable()",
  48.                         MM.BTN_Cancel,    "window.close()",
  49.                                                 MM.BTN_Help,      "displayHelp()");
  50.  
  51. */
  52.  
  53.     var Buttons = new Array( "PutButtonsOnBottom",
  54.                          "OkButton", MM.BTN_OK,     "applyFormatToSelectedTable();window.close();", 
  55.                          "ApplyButton", MM.BTN_Apply,   "applyFormatToSelectedTable()", 
  56.                          "CancelButton", MM.BTN_Cancel,  "window.close()",
  57.                          "PutButtonOnLeft", MM.BTN_Help,    "displayHelp()");
  58.  
  59.   if (isUnrecognizedTable(tableObj) || hasCaption(tableObj))
  60.     Buttons=new Array(MM.BTN_OK,"window.close()",
  61.                       MM.BTN_Cancel,"window.close()");
  62.  
  63.   return Buttons;
  64. }
  65.  
  66. function canAcceptCommand(){
  67.   if (dw.getDocumentDOM() == null)
  68.       return false;
  69.   else if (dw.getFocus() != 'document')
  70.     return false;
  71.   else if (dw.getDocumentDOM().getParseMode() != 'html')
  72.     return false;
  73.   else if (dw.getDocumentDOM().isTableLocked())
  74.     return false;
  75.   else if (dw.getDocumentDOM().getShowLayoutView())
  76.     return false;
  77.   else if (dw.getDocumentDOM().getCCSharedSetting_TextOnlyInNonTemplates())
  78.     return false;
  79.   else if (findTable())
  80.     return true;
  81.   else
  82.     return false;
  83. }
  84.  
  85. function showIf() {
  86.   return CCWorkspaceManager.getManager(dw.getDocumentDOM()) != null &&
  87.     (CCWorkspaceManager.getManager(dw.getDocumentDOM()).shouldUseDefaultEditor());
  88. }
  89.  
  90.  
  91. //***************** LOCAL FUNCTIONS  ******************
  92.  
  93. function findTable(){
  94.   var tableObj="";
  95.   var selObj = dw.getDocumentDOM().getSelectedNode();
  96.  
  97.   while (tableObj=="" && selObj.parentNode){
  98.     if (selObj.nodeType == Node.ELEMENT_NODE && selObj.tagName=="TABLE")
  99.       tableObj=selObj;
  100.     else
  101.       selObj = selObj.parentNode;
  102.   }
  103.   return tableObj;
  104. }
  105.  
  106. function updatePreview(){
  107.   alternateRows(dwscripts.findDOMObject("presetNames").selectedIndex,getPreviewTable());
  108. }
  109.  
  110. function removeTag( theObj, Tag )
  111. {
  112.     var children   = theObj.childNodes;
  113.     var nChildren  = children.length;
  114.  
  115.     for( var i = 0; i < nChildren; i++ )
  116.     {
  117.          var currentChild = children.item(i);
  118.  
  119.          if ( currentChild.hasChildNodes() )
  120.             removeTag( currentChild, Tag );
  121.  
  122.          if ( currentChild.nodeType == Node.ELEMENT_NODE &&
  123.               currentChild.tagName == Tag )
  124.               currentChild.outerHTML = currentChild.innerHTML;
  125.      }
  126. }
  127.  
  128.  
  129. function applyFormatToSelectedTable(){
  130.  
  131.   var selObj,selArr;
  132.     var dom = dw.getDocumentDOM()
  133.   
  134.   // get current selection
  135.   selArr = dom.getSelection();
  136.   selObj = dom.offsetsToNode(selArr[0],selArr[1]);
  137.       
  138.   alternateRows(dwscripts.findDOMObject("presetNames").selectedIndex,findTable());
  139.   
  140.   // restore original selection, if it still exists; if not, just select the table.
  141.   if (dw.nodeExists(selObj)){
  142.     selArr = dom.nodeToOffsets(selObj);
  143.   }else{
  144.     selArr = dom.nodeToOffsets(findTable());
  145.   }
  146.   dom.setSelection(selArr[0],selArr[1]);
  147.   
  148.   savePreferences();
  149. }
  150.  
  151. function isUnrecognizedTable(tableObj) { //checks selected table
  152.   var counter=0;
  153.   var trIter = tableObj.childNodes;
  154.   var trNode=trIter.item(counter);
  155.   var retVal=false;
  156.   while (trNode && !retVal) {
  157.     if (trNode.tagName!="TR" || trNode.childNodes.length==0) 
  158.       retVal=true;
  159.     else trNode=trIter.item(++counter)
  160.   }
  161.   return retVal;
  162. }
  163.  
  164. function hasCaption(theObj){
  165.   if (theObj.childNodes.item(0).tagName && theObj.childNodes.item(0).tagName=="CAPTION")
  166.     return true;
  167.   return false;
  168. }
  169.  
  170. function initializeUI() { //fill presetNames list
  171.   var tab0 = dwscripts.findDOMObject("Tab0");
  172.   var tab1 = dwscripts.findDOMObject("Tab1");
  173.  
  174.   //Use appropriate background & tabs for Mac OS X.
  175.   if (dw.isOSX()) {
  176.     dwscripts.findDOMObject("tabBgWin").src = "../Shared/MM/Images/tabBgMacFormatTable.gif";
  177.     var oldMulti = RegExp.multiline;
  178.     RegExp.multiline = true;
  179.     var pat1 = /tabBg\.gif/;
  180.     tab0.innerHTML = tab0.innerHTML.replace(pat1, "tabBgOSX.gif");
  181.       tab1.innerHTML = tab1.innerHTML.replace(pat1, "tabBgOSX.gif");
  182.     var pat2 = /tabBgSel\.gif/;
  183.     tab0.innerHTML = tab0.innerHTML.replace(pat2, "tabBgSelOSX.gif");
  184.     tab1.innerHTML = tab1.innerHTML.replace(pat2, "tabBgSelOSX.gif");
  185.     RegExp.multiline = oldMulti;
  186.        var bgImage = findObject("tabBgWin");
  187.       bgImage.width = 470;
  188.     window.resizeToContents();
  189.   // Use appropriate background & tabs for WinXP with themes  
  190.   } else if (dw.isXPThemed()) {
  191.     dwscripts.findDOMObject("tabBgWin").src = "../Shared/MM/Images/tabBgWinXP335x290.gif";
  192.     var oldMulti = RegExp.multiline;
  193.     RegExp.multiline = true;
  194.     var pat1 = /tabBg\.gif/;
  195.     tab0.innerHTML = tab0.innerHTML.replace(pat1, "tabBgXP.gif");
  196.       tab1.innerHTML = tab1.innerHTML.replace(pat1, "tabBgXP.gif");
  197.     var pat2 = /tabBgSel\.gif/;
  198.     tab0.innerHTML = tab0.innerHTML.replace(pat2, "tabBgSelXP.gif");
  199.     tab1.innerHTML = tab1.innerHTML.replace(pat2, "tabBgSelXP.gif");
  200.     RegExp.multiline = oldMulti;
  201.   // Use standard background  
  202.   } else {    
  203.     findObject("tabBgWin").src = "../Shared/MM/Images/tabBgWin335x290.gif";
  204.   }
  205.  
  206.    //Initialize the TabControl.  (Pass in the prefix used for the tab layers)
  207.    T = new TabControl('Tab');
  208.  
  209.    //Add tab pages.   (Pass the layer name, and the page object)
  210.    T.addPage('mainLayer', new Pg1(LABEL_BasicTab));
  211.    T.addPage('advancedLayer', new Pg2(LABEL_AdvancedTab));
  212.  
  213.    T.addGroup("default", new Array("mainLayer","advancedLayer"));
  214.    T.showGroup("default");
  215.  
  216.    //Initialize and display the tabs.  (Could pass the name of a page to start on)
  217.    T.start();
  218.  
  219.   var mainLayer=dwscripts.findDOMObject("mainLayer");
  220.   var presetNamesList,nSize,Names,i;
  221.   var tableObj=findTable();
  222.   var selectedFormat;
  223.  
  224.  if (hasCaption(tableObj))
  225.      mainLayer.innerHTML="<p> </p>" + MSG_CaptionIsPresent;
  226.  else if (isUltraDev() && hasServerBehaviorApplied(tableObj)) {
  227.      mainLayer.innerHTML = "<p> </p>" + MM.MSG_RegionServerBehaviorsNotAllowed;
  228.  } else if (isUnrecognizedTable(tableObj))
  229.  {
  230.     mainLayer.innerHTML="<p> </p>" + MSG_IsInvalidTable; //show error message
  231.     T.removePage('advancedLayer');  //remove advanced tab
  232.     T.refresh();                    //redraw screen so adv tab is gone
  233.  }
  234.  else {
  235.       //add select list options
  236.       mainLayer.visibility="hidden";
  237.       for (i=0;i<4;i++){  //populate select lists
  238.         dwscripts.findDOMObject("topRowAlign").options[i] = new Option(OPTIONS_Align[i]);
  239.         dwscripts.findDOMObject("topRowTextStyle").options[i]=new Option(OPTIONS_Text_Style[i]);
  240.         dwscripts.findDOMObject("leftColAlign").options[i] = new Option(OPTIONS_Align[i]);
  241.         dwscripts.findDOMObject("leftColTextStyle").options[i] = new Option(OPTIONS_Text_Style[i]);
  242.         dwscripts.findDOMObject("rowLimit").options[i] = new Option(OPTIONS_Row_Limit[i]);
  243.       }
  244.       dwscripts.findDOMObject("rowLimit").options[4] = new Option(OPTIONS_Row_Limit[4]);
  245.  
  246.     presetNamesList = dwscripts.findDOMObject("presetNames");
  247.     Names=tableFormats();  //get list of table format names from tableFormats.js file
  248.     nSize = Names.length;
  249.     for (i=0;i<nSize;i++) { 
  250.       presetNamesList.options[i] = new Option(Names[i].name); //populate form field
  251.     }
  252.     dwscripts.findDOMObject("mainLayer").visibility="visible";
  253.     
  254.     selectedFormat = getFormatPreference();
  255.     setUI(selectedFormat); //choose preferred format
  256.     alternateRows(selectedFormat,getPreviewTable()); //apply this format to preview table
  257.     presetNamesList.selectedIndex=selectedFormat; //select default format
  258.  } 
  259.  
  260. }
  261.  
  262.  
  263. function alternateRowColors(trIter,firstRowColor,secondRowColor,rowLimit,useTD,topRowColor){
  264.   var rowLen=trIter.length;
  265.   var cellLen,tdNode,trNode,counter;
  266.   if (rowLimit==0) rowLimit=1000; //repeat first color if rowLimit is equal to 0 
  267.   var counter=2*rowLimit;
  268.   var startRow = (topRowColor)?1:0;
  269.   for (i=startRow;i<rowLen;i++){
  270.     trNode=trIter.item(i);
  271.     rowColor=(counter%(2*rowLimit)<rowLimit)?firstRowColor:secondRowColor;
  272.     if (!useTD){
  273.       // attach bgcolor attribute to tr tags
  274.       trNode.setAttribute("bgcolor",rowColor);
  275.       // remove bgcolor from td tags, so they don't override
  276.       tdIter=trNode.childNodes; cellLen=tdIter.length;
  277.       for (j=0;j<cellLen;j++){
  278.         if (tdIter.item(j).getAttribute("bgcolor") != null && tdIter.item(j).getAttribute("bgcolor") != undefined){   
  279.           tdIter.item(j).removeAttribute("bgcolor"); 
  280.         }
  281.       }
  282.     } 
  283.     else {
  284.       // attach bgcolor attribute to td tags
  285.       // remove tr settings, if any (they're useless now)
  286.       if (trNode.getAttribute("bgcolor") != null && trNode.getAttribute("bgcolor") != undefined){
  287.         trNode.removeAttribute("bgcolor");
  288.       }
  289.       tdIter=trNode.childNodes; cellLen=tdIter.length;
  290.       for (j=0;j<cellLen;j++) 
  291.         tdIter.item(j).setAttribute("bgcolor",rowColor);
  292.     }
  293.     counter++; 
  294.   }
  295. }
  296.  
  297. function formatTopRow(trIter,topRowColor,topRowTextColor,topRowTextStyle,topRowAlign,useTD){
  298.   var trNode=trIter.item(0), cellLen;
  299.  
  300.   //add bgcolor & align
  301.   if (!useTD) { 
  302.     // attach bgcolor & align to first row TR tag. make sure to
  303.     // remove settings from TDs to prevent them overriding the TR settings.
  304.     if (topRowColor){
  305.         trNode.setAttribute("bgcolor",topRowColor);
  306.       tdIter=trNode.childNodes; cellLen=tdIter.length;
  307.       for (i=0;i<cellLen;i++){
  308.         tdNode=tdIter.item(i);
  309.         if (tdNode.getAttribute("bgcolor") != null && tdNode.getAttribute("bgcolor") != undefined){
  310.           tdNode.removeAttribute("bgcolor");
  311.         }
  312.       }
  313.     }
  314.       if ( !topRowAlign || topRowAlign.toLowerCase() == "none" ){
  315.         trNode.removeAttribute("align");
  316.     }else{
  317.       trNode.setAttribute("align",topRowAlign);
  318.       tdIter=trNode.childNodes; cellLen=tdIter.length;
  319.       for (i=0;i<cellLen;i++){
  320.         tdNode=tdIter.item(i);
  321.         if (tdNode.getAttribute("align") != null && tdNode.getAttribute("align") != undefined){
  322.           tdNode.removeAttribute("align");
  323.         }
  324.       }
  325.     }
  326.   } else { 
  327.     // attach bgcolor & align to TD tags in first row
  328.     // remove settings from TR tag (they're useless now)
  329.     tdIter=trNode.childNodes; cellLen=tdIter.length;
  330.     for (i=0;i<cellLen;i++){
  331.       tdNode=tdIter.item(i);
  332.         if (topRowColor)
  333.         tdNode.setAttribute("bgcolor",topRowColor);
  334.       if ( !topRowAlign || topRowAlign.toLowerCase()=="none" )
  335.           tdNode.removeAttribute("align");
  336.       else
  337.           tdNode.setAttribute("align",topRowAlign);      
  338.     }
  339.     if (trNode.getAttribute("bgcolor") != null && trNode.getAttribute("bgcolor") != undefined){
  340.       trNode.removeAttribute("bgcolor");
  341.     }
  342.     if (trNode.getAttribute("align") != null && trNode.getAttribute("align") != undefined){
  343.       trNode.removeAttribute("align");
  344.     }
  345.   } 
  346.  
  347.   //add text color and text formatting
  348.   tdIter=trNode.childNodes; cellLen=tdIter.length;
  349.    for (i=0;i<cellLen;i++) {
  350.      tdNode=tdIter.item(i);
  351.      //set font color, if specified
  352.      if (topRowTextColor){
  353.        if (!findTag(tdNode,"FONT")){ //if the color attribute cannot be added to a "safe" font tag, add it.
  354.          tdNode.innerHTML='<font color="' + topRowTextColor + '">' + tdNode.innerHTML + '</font>';
  355.        }
  356.        else  { //font tag already exists, set color attribute on it
  357.          findTag(tdNode,"FONT").setAttribute("color",topRowTextColor);
  358.        }
  359.          //remove font color if NOT specified
  360.      }else{
  361.         var fontTag = findTag(tdNode,"FONT");
  362.                  if (fontTag && fontTag.getAttribute("color")){
  363.                     fontTag.removeAttribute("color");
  364.           if (fontTag.attributes.length == 0){
  365.             removeTag(tdNode,"FONT");
  366.           }
  367.                 }
  368.             }
  369.       //set text style
  370.      if (topRowTextStyle==0){//if text style set to none
  371.        removeTag(tdNode,"B"); //remove bold tags
  372.        removeTag(tdNode,"I"); //and remove italic tags
  373.      } else {
  374.        if (topRowTextStyle==1 || topRowTextStyle==3){ //if bold or bold italic
  375.          if (topRowTextStyle==1) //if bold
  376.            removeTag(tdNode,"I"); //remove all italic tags
  377.          if (!findTag(tdNode,"B")){ //if a B tag is not found around the table cell text
  378.            removeTag(tdNode,"B"); //remove any other B tags
  379.            tdNode.innerHTML="<b>" + tdNode.innerHTML + "</b>"; //make first child a B tag
  380.          }
  381.        }
  382.        if (topRowTextStyle==2 || topRowTextStyle==3){ //if italic or or bold italic
  383.          if (topRowTextStyle==2) //if italic
  384.            removeTag(tdNode,"B"); //remove all bold tags
  385.          if (!findTag(tdNode,"I")){ //if an I tag is not found around the table cell text 
  386.            removeTag(tdNode,"I"); //remove any other I tags
  387.            tdNode.innerHTML="<i>" + tdNode.innerHTML + "</i>"; //make first child an I tag
  388.          }
  389.        }
  390.      }
  391.    } 
  392. }
  393.  
  394. function formatLeftCol(trIter,leftColTextStyle,leftColAlign){
  395.   rowLen=trIter.length;
  396.    for (i=0;i<rowLen;i++){
  397.      trNode=trIter.item(i);
  398.      tdNode=trNode.childNodes.item(0);
  399.      //set text style
  400.      if (leftColTextStyle==0){ //if text style set to none
  401.        removeTag(tdNode,"B"); //remove bold tags
  402.        removeTag(tdNode,"I"); //and remove italic tags
  403.      }
  404.      else {
  405.        if (leftColTextStyle==1 || leftColTextStyle==3){ //if text style set to bold or bold italic
  406.          if (leftColTextStyle==1) //if bold
  407.            removeTag(tdNode,"I"); //remove all italic tags
  408.          if (!findTag(tdNode,"B")){ //if B tag is not found around text
  409.            removeTag(tdNode,"B"); //remove all other B tags
  410.            tdNode.innerHTML="<b>" + tdNode.innerHTML + "</b>"; //make first child a B tag
  411.          }
  412.     
  413.        }
  414.        if (leftColTextStyle==2 || leftColTextStyle==3){ //if text style is set to italic or bold italic
  415.          if (leftColTextStyle==2) //if italic
  416.            removeTag(tdNode,"B"); //remove all bold tags
  417.          if (!findTag(tdNode,"I")){ //if i tag is not found around text
  418.            removeTag(tdNode,"I"); //remove all other i tags
  419.            tdNode.innerHTML="<i>" + tdNode.innerHTML + "</i>"; //make first child tag i tag
  420.          }
  421.        }
  422.      }     
  423.      //set alignment
  424.      if ( !leftColAlign || leftColAlign.toLowerCase()=="none" )
  425.        tdNode.removeAttribute("align");
  426.      else
  427.        tdNode.setAttribute("align",leftColAlign);        
  428.    }
  429. }
  430.  
  431. function setUI(presetIndex){
  432.       var Names = tableFormats();
  433.       var thisFormat = Names[presetIndex];               
  434.       with (thisFormat){
  435.         //error check rowLimit value
  436.         if (rowLimit>4 || rowLimit<0)rowLimit=1;
  437.     
  438.         //align attributes are specified as "left","center","right", and "";
  439.         //following function gets correct selected index for alignment option
  440.         topRowAlign=getIndex(topRowAlign);
  441.         leftColAlign=getIndex(leftColAlign); 
  442.         //select the appropriate options
  443.         dwscripts.findDOMObject("rowLimit").selectedIndex=parseInt(rowLimit);
  444.         dwscripts.findDOMObject("topRowAlign").selectedIndex=topRowAlign;
  445.         dwscripts.findDOMObject("topRowTextStyle").selectedIndex=topRowTextStyle;
  446.         dwscripts.findDOMObject("leftColAlign").selectedIndex=leftColAlign;
  447.         dwscripts.findDOMObject("leftColTextStyle").selectedIndex=leftColTextStyle;
  448.       
  449.         //fill in textfields
  450.         dwscripts.findDOMObject("firstRowColor").value = firstRowColor;
  451.         dwscripts.findDOMObject("firstRow").value = firstRowColor;
  452.         dwscripts.findDOMObject("secondRowColor").value = secondRowColor;
  453.         dwscripts.findDOMObject("secondRow").value = secondRowColor;
  454.         dwscripts.findDOMObject("topRow").value = topRowColor;
  455.         dwscripts.findDOMObject("topRowColor").value = topRowColor;
  456.         dwscripts.findDOMObject("topRowTextColor").value = topRowTextColor;
  457.         dwscripts.findDOMObject("topRowText").value = topRowTextColor;
  458.         dwscripts.findDOMObject("borderSize").value = border;
  459.       }
  460.  
  461. }
  462. function alternateRows(presetChoiceIndex,tableObj){
  463.   var tableNode,trIter,trNode,tdIter,tdNode,counter;
  464.   var useTD,topRowColor,selInd,topRowAlign,topRowTextColor;
  465.   var topRowTextStyle,firstRowColor,secondRowColor;
  466.   var rowLimit,borderSize;
  467.  
  468.   tableNode=tableObj;
  469.   trIter=tableNode.childNodes;
  470.   useTD=false;
  471.   
  472.   //The rest of the function assigns values to below variables based on user interface.
  473.   //User interface is initially populated with argument values, but the user can change
  474.   //them to dynamically update the preview table.
  475.  
  476.   //set variables for the top row
  477.   topRowColor=dwscripts.findDOMObject('topRowColor').value;
  478.   selInd = dwscripts.findDOMObject('topRowAlign').selectedIndex;
  479.   topRowAlign=dwscripts.findDOMObject('topRowAlign').options[selInd].value;
  480.   topRowTextColor=dwscripts.findDOMObject('topRowTextColor').value;
  481.   topRowTextStyle=dwscripts.findDOMObject('topRowTextStyle').selectedIndex;
  482.   
  483.   //set variables for the left col
  484.   selInd = dwscripts.findDOMObject('leftColAlign').selectedIndex;
  485.   leftColAlign=dwscripts.findDOMObject('leftColAlign').options[selInd].value;
  486.   leftColTextStyle=dwscripts.findDOMObject('leftColTextStyle').selectedIndex;
  487.   
  488.   //set variables for the row Colors
  489.   firstRowColor=dwscripts.findDOMObject('firstRowColor').value;
  490.   secondRowColor=dwscripts.findDOMObject('secondRowColor').value;
  491.   rowLimit=dwscripts.findDOMObject("rowLimit").selectedIndex;
  492.   
  493.   //set border size
  494.   borderSize=dwscripts.findDOMObject("borderSize").value;
  495.  
  496.   //Now, use these values to format the table...
  497.   
  498.   //set table border
  499.   tableNode.setAttribute("border",borderSize); 
  500.  
  501.   //alternate row Colors  
  502.   alternateRowColors(trIter,firstRowColor,secondRowColor,rowLimit,useTD,topRowColor);
  503.  
  504.   //add left col formatting:text style & alignment
  505.   formatLeftCol(trIter,leftColTextStyle,leftColAlign);
  506.  
  507.   //add top row formatting:text style,alignent,row color, & text color
  508.   formatTopRow(trIter,topRowColor,topRowTextColor,topRowTextStyle,topRowAlign,useTD);
  509.   
  510.   //set border
  511.   tableNode.setAttribute("border",borderSize);
  512.  
  513.   //if there is a background color, remove it.
  514.   if (tableNode.getAttribute("bgColor")) {
  515.     tableNode.removeAttribute("bgColor");
  516.   }
  517. }
  518.  
  519. function updatePreviewTable(){
  520.   var presetIndex = dwscripts.findDOMObject("presetNames").selectedIndex;
  521.   var previewTable = getPreviewTable();
  522.   var mainLayer = dwscripts.findDOMObject("mainLayer");
  523.   
  524.   setUI(presetIndex);
  525.   alternateRows(dwscripts.findDOMObject("presetNames").selectedIndex,previewTable);//format table
  526. }
  527.  
  528. function getPreviewTable(){
  529.    //returns preview Table object
  530.    return document.getElementsByTagName("TABLE").item(1);
  531. }
  532.  
  533.  
  534. function getIndex(align){
  535.   //returns align index of UI that matches text of align argument i.e: "center"
  536.   //Note: I didn't use constants here because it is more intuitive to define
  537.   //the alignment attribute following the html syntax of align="attribute"
  538.     switch (align){
  539.      case "left": align=1; break;
  540.      case "center": align=2; break;
  541.      case "right": align=3; break;
  542.      default: align=0; break;
  543.    }
  544.  return align;
  545. }
  546.  
  547. //searches the child nodes of tableCellObj -
  548. //returns the innermost object of tagName that surrounds all of the text in
  549. //the cell. returns empty string if not found.
  550. function findTag(obj, tag) {
  551.   var retVal="";
  552.   while (obj.childNodes && obj.childNodes.length == 1) {
  553.     obj = obj.childNodes.item(0);
  554.    if (obj.nodeType == Node.ELEMENT_NODE && obj.tagName == tag)
  555.      retVal=obj;
  556.   }
  557.   return retVal;
  558.  
  559. }
  560.  
  561.  
  562. function getFormatPreference() {
  563.   var metaFile, savedVal, curVal = DEFAULT_tableStyle;
  564.   if (typeof MMNotes != 'undefined') { // Check for MMNotes extension.
  565.    metaFile = MMNotes.open(document.URL, false);
  566.    if (metaFile) {
  567.      // Form specific settings.
  568.      savedVal = MMNotes.get(metaFile, 'MM_pref_FormatTable');
  569.      MMNotes.close(metaFile);
  570.      if (curVal == parseInt(curVal).toString()) {
  571.        curVal = savedVal;
  572.      }
  573.    }
  574.   }
  575.   return parseInt(curVal);
  576. }
  577.  
  578. function savePreferences() {
  579.   if (typeof MMNotes == 'undefined') {return;} // Check for MMNotes extension.
  580.   var metaFile, curVal;
  581.   metaFile = MMNotes.open(document.URL, true);
  582.   if (metaFile) {
  583.     curVal = MMNotes.set(metaFile, 'MM_pref_FormatTable', findObject("presetNames").selectedIndex);
  584.     MMNotes.close(metaFile);
  585.   }
  586. }
  587.